import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;

import java.io.File;

/**
 * Created by admin on 2017/3/14.
 */
public class addFiletoZip {
    private static final String FILE_DEST = "E:\\新版资料";
    private static final String DEST_SPERATOR = "_";
    private static final String DEST_SUFFIX = ".zip";




    public static void main(String[] args) {
         File file = new File("E:\\博学谷\\JavaEEV0.1\\淘淘商城\\02.课件");
        flodersToZip(file);
       // System.out.println(" = ");
      //  addFloderTest1();
    }

    public static void flodersToZip(File file) {
        File[] files = file.listFiles();
        if(files.length > 0) {
            File[] arr$ = files;
            int len$ = files.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                File f = arr$[i$];
                File destFile = new File("E:\\新版资料" + File.separator + f.getParentFile().getName() + DEST_SPERATOR+ f.getName() + ".zip");
                FlodersToZip(f, destFile);
            }
        }

    }

    public static void FlodersToZip(File file, File dest) {
        ZipFile zipFile = null;
        try{

            zipFile = new ZipFile(dest);
        } catch (ZipException e) {
            e.printStackTrace();
        }

        File[] files = file.listFiles();
        if(files!=null && files.length>0){
        File[] arr$ = files;
            int len$ = files.length;

            for(int i$ = 0; i$ < len$; ++i$) {
                File f = arr$[i$];
                if(f.isDirectory() && !f.getName().equals("视频")) {
                    addFloder(zipFile, f);
                }
            }
        }

    }

    public static void addFloder(ZipFile zipFile, File file) {
        ZipParameters parameters = new ZipParameters();
        parameters.setCompressionMethod(8);
        parameters.setCompressionLevel(5);

        try {
            zipFile.addFolder(file.getAbsolutePath(), parameters);
        } catch (ZipException var4) {
            var4.printStackTrace();
        }

    }
    public static void addFloderTest1(){
        try {
            // Initiate ZipFile object with the path/name of the zip file.

            ZipFile zipFile = new ZipFile("E:\\博学谷\\JavaEEV0.1\\java基础\\第一阶段_day01.zip");

            // Folder to add
            String folderToAdd = "E:\\博学谷\\JavaEEV0.1\\java基础\\第一阶段\\day01\\code";

            // Initiate Zip Parameters which define various properties such
            // as compression method, etc.
            ZipParameters parameters = new ZipParameters();

            // set compression method to store compression
            parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);

            // Set the compression level
            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

            // Add folder to the zip file
            zipFile.addFolder(folderToAdd, parameters);

        } catch (ZipException e) {
            e.printStackTrace();
        }
    }
}
